package com.henz4help.app.common;

import com.henz4help.app.R;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

public class InputDialog extends Dialog {
	private Context mContext;
	private EditText mEdtBox;
	private TextView mTxvTitle;
	private Button mBtnComplete;
	private Button mBtnCancel;
	private AppInfo mAppInfo;
	
	public InputDialog(Context context, int theme) {
		super(context, theme);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		mContext = context;
		mAppInfo = AppInfo.getInstance(mContext);
		
		LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		LayoutParams params = new LayoutParams(mAppInfo.getmDisplayWidth()-40, LayoutParams.WRAP_CONTENT);
		
		View layout = inflater.inflate(R.layout.inputbox, null);
		setContentView(layout, params);
		
		mEdtBox = (EditText)layout.findViewById(R.id.edtBoxInput);

		InputMethodManager ime = (InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
        ime.showSoftInputFromInputMethod(mEdtBox.getWindowToken(), InputMethodManager.SHOW_FORCED);
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
        
        mTxvTitle = (TextView)layout.findViewById(R.id.txvTitleInput);
        mBtnComplete = (Button)layout.findViewById(R.id.btnComplete);
        mBtnCancel = (Button)layout.findViewById(R.id.btnCancel);
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}
	
	public void setText(String text) {
		mTxvTitle.setText(text);
	}
	
	public void setEdit(String content) {
		mEdtBox.setText(content);
	}
	
	public String getEdit() {
		return mEdtBox.getText().toString();
	}
	
	public void setCompleteListener(Button.OnClickListener listener) {
		mBtnComplete.setOnClickListener(listener);
	}
	
	public void setCancelListener(Button.OnClickListener listener) {
		mBtnCancel.setOnClickListener(listener);
	}
}
